home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4575 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  45 lines

  1. Path: jaxnet.jaxnet.com!jax!garyg
  2. From: garyg@jax.jaxnet.com (Gary M. Greenberg)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Command line Arguments
  5. Date: 5 Feb 1996 22:29:46 GMT
  6. Organization: Southeast Network Services, Inc.
  7. Message-ID: <4f60cr$34v@jaxnet.jaxnet.com>
  8. References: <4f2qev$9jq@cloner3.netcom.com>
  9. NNTP-Posting-Host: jax.jaxnet.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Glen 'Steve' Vandiver (buxx@ix.netcom.com) wrote:
  13. : Hi! I have been haveing trouble with my commandline arguements. I have
  14. : it too where i can read the entire argument string after the run. No
  15. : prob. but lets say i want it to split it up like this. the first word
  16. : goes into char *user; and the rest goes into char *command;. HOW WOULD
  17. : I DO THIS? thanx! bye!
  18.  
  19. I think this is what you mean:
  20.  
  21. #include <stdio.h>
  22. #include <string.h>
  23. #define LEN 256
  24. int main (int argc,char **argv)
  25. {
  26.  
  27.     char user[LEN], command[LEN*4];
  28.     int i;
  29.     if(argc<3) {
  30.         printf("Enter more command line args. Bye\n");
  31.         exit (1);
  32.     }
  33.     strcpy(user,argv[1]);
  34.     for(i=2;i<argc;i++)
  35.         strcat(command,argv[i]);
  36.     printf("User: %s\tCommand: %s\n",user,command);
  37.     return 0;
  38. }
  39.  
  40. gary    /* the Sorcerer's Apprentice */
  41.  
  42. "Why do we have to hide from the police, Daddy?"
  43. "Because we use vi, honey. They use emacs."
  44. "Unless we're on the Mac. Then we use BBEdit 'cause 'It doesn't suck.'"
  45.